package com.blrs.controller;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse;

import com.blrs.common.annotation.Anonymous;
import com.blrs.common.annotation.RepeatSubmit;
import com.blrs.common.utils.SecurityUtils;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.domain.ActivityReception;
import com.blrs.domain.ActivityRegistration;
import com.blrs.domain.ActivityTraining;
import com.blrs.domain.vo.RegisterVO;
import com.blrs.service.activity.IActivityReceptionService;
import com.blrs.service.activity.IActivityRegistrationService;
import com.blrs.service.activity.IActivityTrainingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 活动信息培训Controller
 * 
 * @author yang
 * @date 2023-11-22
 */
@RestController
@RequestMapping("/activity/training")
public class ActivityTrainingController extends BaseController
{
    @Autowired
    private IActivityTrainingService activityTrainingService;
    @Autowired
    private IActivityRegistrationService activityRegistrationService;
    @Autowired
    private IActivityReceptionService activityReceptionService;

    /**
     * 查询活动信息培训列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ActivityTraining activityTraining)
    {
        startPage();
        List<ActivityTraining> list = activityTrainingService.selectActivityTrainingList(activityTraining);
        return getDataTable(list);
    }


    /**
     * 获取公共端所有的一键发送活动列表
     */
    @GetMapping("/getActivityOneList")
    @Anonymous
    public TableDataInfo getActivityOneList(ActivityTraining activityTraining){
        startPage();
        List<ActivityTraining> list =activityTrainingService.selectActivityTypeOneList(activityTraining);
        return getDataTable(list);
    }


    @GetMapping("/listOrgId")
    public TableDataInfo listOrgId(ActivityTraining activityTraining)
    {
        startPage();
        List<ActivityTraining> list = activityTrainingService.selectActivityTrainingByOrgId(activityTraining);
        return getDataTable(list);
    }
//    /**
//     * 根据客户id获取活动信息培训信息列表
//     */
//    @GetMapping(value = "/listByEnterpriseId")
//    public TableDataInfo listByEnterpriseId(ActivityTraining activityTraining)
//    {
//        startPage();
//        List<ActivityTraining> list = activityTrainingService.selectActivityTrainingByEnterpriseIdList(activityTraining);
//        return getDataTable(list);
//    }
    /**
     * 查询活动信息培训前4条（公共端）
     */
    @GetMapping("/publicList")
    @Anonymous
    public TableDataInfo publicList(ActivityTraining activityTraining)
    {
        startPage();
        List<ActivityTraining> list = activityTrainingService.selectActivityTrainingPublicList(activityTraining);
        return getDataTable(list);
    }


    /**
     * 导出活动信息培训列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivityTraining activityTraining)
    {
        List<ActivityTraining> list = activityTrainingService.selectActivityTrainingList(activityTraining);
        ExcelUtil<ActivityTraining> util = new ExcelUtil<ActivityTraining>(ActivityTraining.class);
        util.exportExcel(response, list, "活动信息培训数据");
    }

    /**
     * 获取活动信息培训详细信息
     */
    @GetMapping(value = "/{activityId}")
    @Anonymous
    public AjaxResult getInfo(@PathVariable("activityId") String activityId)
    {
        return success(activityTrainingService.selectActivityTrainingByActivityId(activityId));
    }

    /**
     * 新增活动信息培训
     */
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody ActivityTraining activityTraining) throws NoSuchFieldException, IllegalAccessException {
        return toAjax(activityTrainingService.insertActivityTraining(activityTraining));
    }

    /**
     * 修改活动信息培训
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityTraining activityTraining)
    {
        return activityTrainingService.updateActivityTraining(activityTraining);
    }

    /**
     * 删除活动信息培训
     */
	@DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable String[] activityIds)
    {
        return toAjax(activityTrainingService.deleteActivityTrainingByActivityIds(activityIds));
    }
    /**
     * 审核通过活动信息培训
     */
    @PostMapping("/updateStatus/examine")
    public AjaxResult examine(@RequestBody ActivityTraining activityTraining){
        return activityTrainingService.updateActivityStatus(activityTraining);
    }

    /**
     * 接收方查询活动信息列表
     */
    @GetMapping("/receive/list")
    public TableDataInfo receiveList(ActivityTraining activityTraining)
    {
        startPage();
        List<ActivityTraining> list = activityTrainingService.selectActivityTrainingListRecive(activityTraining);
        return getDataTable(list);
    }

    /**
     * 客户管理查询入驻企业活动列表（已报名）
     */
    @GetMapping("/listByEnterpriseId")
        public TableDataInfo listByEnterpriseId(ActivityTraining activityTraining)
    {
        startPage();
        List<ActivityTraining> list= Collections.emptyList();
        if (Objects.nonNull(activityTraining.getSponsor())){
            list= activityTrainingService.selectActivityTrainingListReciveList(activityTraining);
        }
        return getDataTable(list);
    }
    /**
     * 审核方查询活动信息列表
     */
    @GetMapping("/examine/list")
    public TableDataInfo examineList(ActivityTraining activityTraining)
    {
        startPage();
        List<ActivityTraining> list = activityTrainingService.selectActivityTrainingListExamnie(activityTraining);
        return getDataTable(list);
    }

    /**
     * 接收方报名
     */
     @GetMapping("/receive/application/{activityId}")
    public AjaxResult app(@PathVariable(name = "activityId")String activityId){
         return toAjax(activityRegistrationService.insertActivityApp(activityId));
     }
    /**
     * 查询报名情况列表
     */
    @GetMapping("/reception/list")
    public TableDataInfo receptionList(ActivityReception activityReception)
    {
        startPage();
        List<ActivityReception> list = activityReceptionService.selectActivityReceptionList(activityReception);
        return getDataTable(list);
    }
    /**
     * 查询报名企业人员
     */
    @GetMapping("/regi/list")
    public TableDataInfo regiList(ActivityRegistration activityRegistration)
    {
        startPage();
        List<ActivityRegistration> list = activityRegistrationService.selectActivityRegistrationByActivityId(activityRegistration);
        return getDataTable(list);
    }
    /**
     * 查询报名企业人员
     */
    @PostMapping("/export/regi")
    public void regiList(HttpServletResponse response,ActivityRegistration activityRegistration)
    {
        List<ActivityRegistration> list = activityRegistrationService.selectActivityRegistrationListExport(activityRegistration);
        ExcelUtil<ActivityRegistration> util = new ExcelUtil<ActivityRegistration>(ActivityRegistration.class);
        util.exportExcel(response, list, "活动信息培训数据");
    }


    /**
     * 评分
     */
    @PostMapping("/score")
    public AjaxResult score(@RequestBody ActivityTraining activityTraining){
        return  toAjax(activityTrainingService.updateActivityTrainingScore(activityTraining));
    }

    /**
     * 一键发送终止审核
     */
    @PostMapping("/termination")
    public AjaxResult termination(@RequestBody ActivityTraining activityTraining){
        return activityTrainingService.terminationActivityTraining(activityTraining);
    }

    /**
     * 查询服务端首页当前企业接收的前三条信息
     */
     @GetMapping("/getTopThree")
     @Anonymous
    public List<ActivityTraining> getTopThree(){
         return activityTrainingService.selectActivityTrainingListTopThree(SecurityUtils.getOrgId());
     }

    /**
     * 查询公共端所有活动类型
     */
    @GetMapping("/getActivityType")
    @Anonymous
    public List<String> getActivityType(){
        return activityTrainingService.selectActivityTypeList();
    }

    /**
     * 公共端查询相关企业5条
     */
    @GetMapping("/getFiveActivity")
    @Anonymous
    public TableDataInfo getFiveActivity(ActivityTraining activityTraining){
        startPage();
       List<ActivityTraining> list=activityTrainingService.selectActivityTrainingByActivityIdFive(activityTraining.getActivityId());
        return getDataTable(list);
    }

    /**
     * 注册报名
     */
    @PostMapping("/register")
    @Anonymous
    public AjaxResult register(@RequestBody RegisterVO registerVO){
        return activityTrainingService.register(registerVO);
    }


}
